<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     default_default
 * @copyright   Copyright (c) 2006-2018 Magento, Inc. (http://www.magento.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
$element = $this->getElement();
$note    = $element->getNote();
$trId    = $element->getHtmlContainerId();
$class   = $element->getFieldsetHtmlClass();
?>
<?php if (!$element->getNoDisplay()): ?>
<tr<?php if($trId): ?> id="<?php echo $trId ?>"<?php endif; ?>>
    <td class="label<?php echo $class ? " {$class}-label" : ''?>"><?php echo $element->getLabelHtml() ?></td>
    <td class="<?php echo $element->hasValueClass() ? $element->getValueClass() : 'value' ?><?php echo $class ? " {$class}-value" : ''?>">
        <div id="countries-control">
            <input type="checkbox" id="select-all" />
                <label for="select-all">
                    <strong><?php echo $this->__('All locations'); ?></strong>
                </label>
        </div>
        <p class="note">
            <?php echo $this->__('(Includes more countries than those listed below. As the application owner, you are responsible for complying with country-specific laws related to the distribution or sale of your application into that country, including your home country.)'); ?>
        </p>
        <?php echo $element->getElementHtml(); ?>
        <?php if ($note): ?>
            <p class="note<?php echo $class ? " {$class}-note" : ''?>" id="note_<?php echo $element->getId(); ?>">
                <span><?php echo $note ?></span>
            </p>
        <?php endif ?>
        <script type="text/javascript">
            function checkCountryValues(click) {
                if (click) {
                    isChecked = $('select-all').checked;
                    $$('#submission-countries-table input[type=checkbox]').each(
                        function(elm) {
                            if (isChecked && !elm.checked) {
                                elm.checked = true;
                            } else if (!isChecked && elm.checked) {
                                elm.checked = false;
                            }
                        }
                        );
                    if (isChecked) {
                        $('submission-countries-table').hide();
                    } else if (!isChecked) {
                        $('submission-countries-table').show();
                    }
                } else {
                    checkboxCount = $$('#submission-countries-table input[type=checkbox]').length;
                    countEnabled = 0;
                    $$('#submission-countries-table input[type=checkbox]').each(
                        function(elm) {
                            if (elm.checked) {
                                countEnabled++;
                            }
                        }
                    );
                    if (countEnabled == checkboxCount) {
                        $('select-all').checked = true;
                        $('submission-countries-table').hide();
                    }
                }
            }
            checkCountryValues(false);

            $('select-all').observe('click', function() {
                checkCountryValues(true);
            });
        </script>
    </td>
</tr>
<?php endif; ?>
